<?php

use yii\db\Migration;

class m000004_000002_create_isp extends Migration
{
    public function safeUp()
    {
        $this->createTable('{{%isp}}', [
            'id' => $this->primaryKey(),
            'name' => $this->string(32)->notNull()->comment('名称'),
            'api_id' => $this->integer()->notNull()->comment('接口编号'),
            'data' => $this->text()->notNull()->comment('数据'),
            'create_time' => $this->integer()->notNull()->comment('创建时间'),
            'status' => $this->integer()->notNull()->comment('状态')
        ]);
        $this->createIndex('fk_isp_api1_idx', '{{%isp}}', ['api_id']);
        try {
            $this->addForeignKey('fk_isp_api1', '{{%isp}}', ['api_id'], '{{%api}}', ['id']);
        } catch (Exception $e) {
            Yii::error($e->getMessage());
        }
        $this->batchInsert('{{%key_map}}', ['t', 'k', 'v'], [
            ['isp_status', 1, '正常'],
            ['isp_status', 0, '删除'],
        ]);
    }

    public function down()
    {
        $this->delete('{{%key_map}}', ['t' => 'isp_status']);
        $this->dropTable('{{%isp}}');
    }
}
